<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>分店批发页面</title>
	<link rel="stylesheet" href="../../res/mln/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 300px; line-height: 300px; text-align: center;}
    .demoTable{
    	z-index: 10px;
    }
    #addReload{
    	position:absolute;
    	top:0%;
    	z-index: 100px;
    	background: rgb(0,0,0,0.9);
    	width:100%;
    	height: 100%;
    	display: none;
    }
    #addOperation{
    	position: absolute;
    	left: 30%;
    	top: 0%;
    	width: 40%;
    	background: white;
    	
    	
    }
     #updateReload{
    	position:absolute;
    	top:0%;
    	z-index: 100px;
    	background: rgb(0,0,0,0.9);
    	width:100%;
    	height: 100%;
    	display: none;
    }
    #updateOperation{
    	position: absolute;
    	left: 30%;
    	top: 0%;
    	width: 40%;
    	background: white;
    	
    	
    }
   
  </style>
</head>
<body>
	<div class="demoTable">
		搜索关键字：
		<div class="layui-inline" >
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		
		时间：
		<div class="layui-input-inline">
      	  	<input name="date" id="dateOne" lay-verify="dateOne" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	——<div class="layui-input-inline">
      	  	<input name="dateTwo" id="dateTwo" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
		<button class="layui-btn" data-type="reload">搜索</button>
		
		
		<table class="layui-hide" id="wholesale" lay-filter="demo"></table>
	</div>
	

 <div id="updateReload">
 		<div id="updateOperation">
		 	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  <legend>会员修改列表</legend>
			</fieldset>
			<form class="layui-form" action="../../member/addOrUpdate.action" method="post"  >
			  <div class="layui-form-item">
			    <label class="layui-form-label">会员名称</label>
			    <div class="layui-input-block">
			      <input type="hidden" name="memberId" id="memberId"  />
			      <input type="text" name="memberName" id="memberName" maxlength="18" min="6" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" style="width:280px;">
			    </div>
			  </div>
			  <div class="layui-form-item">
			    <label class="layui-form-label">会员账号</label>
			    <div class="layui-input-block">
			      <input type="text" name="memberNumber" id="memberNumber" maxlength="18" min="6"  lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input" style="width:280px;">
			    </div>
			  </div>
			  <div class="layui-form-item">
			    <label class="layui-form-label">会员密码</label>
			    <div class="layui-input-block">
			      <input type="password" name="menmberPwd" id="menmberPwd" lay-verify="required" maxlength="18" min="6"  placeholder="请输入密码" autocomplete="off" class="layui-input" style="width:280px;">
			    </div>
			  </div>
			  <div class="layui-form-item">
			        <label class="layui-form-label">会员头像</label>
			        <div class="layui-input-block">
			            <button type="button" class="layui-btn" id="uploadTwo">上传图片</button>
			            <input type="hidden" id="img_urlTwo" name="memberImage" value=""/>
			            <div class="layui-upload-list">
			                <img class="demoTow" width="100px" height="80px" id="demoTow"/>
			                <p id="demoTextTwo"></p>
			            </div>
			        </div>
			  </div>
			  <div class="layui-form-item">
			    <label class="layui-form-label">是否有效</label>
			    <div class="layui-input-block" style="width:200px;">
			      <select name="memberSort" id="isva" lay-verify="required" lay-search="">
			          <option value="0">是</option>
			          <option value="1">否</option>
			       </select>
			    </div>
			  </div>
			  <div class="layui-form-item">
			    <div class="layui-input-block">
			      <input type="submit" class="layui-btn"  value="提交">
			      <button id="closeUpdate" type="reset" class="layui-btn layui-btn-primary" >取消</button>
			    </div>
			  </div>
		 </form>
	 </div>
 </div>
<script type="text/html" id="barDemo">
   <a class="layui-btn layui-btn-xs" lay-event="detail" >查看详情</a>
   {{# if(d.isva==4){ }}
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
   {{# } else if(d.isva==5){}}
        {{# if(d.tuihuo=="0"){ }}
           <a class="layui-btn layui-btn-disabled  layui-btn-xs" lay-event="salesReturn">退货</a>
        {{# } else if(d.tuihuo==1){}}
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="salesReturn">退货</a>
		{{# } }}

   {{# }else if(d.isva==3){}}
   <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="xgsh">修改</a>
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } }}





</script>

<script src="../../res/js/jquery-1.10.2.js"></script>
	<script src="../../res/js/layui-xtree.js"></script>
	<script src="../../layui/layui.js"></script>
	<script src="../../res/js/base.js"></script>

<script>

layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  var path=getRootPath();
  var endDate= laydate.render({
      elem: '#dateTwo',//选择器结束时间
      //type: 'datetime',
      min:"2001-12-31",//设置min默认最小值  0表示今天 -1表示昨天  1表示明天
      max:"2099-12-31",
      done: function(value,date){
          startDate.config.max={
              year:date.year,
              month:date.month-1,//关键
              date: date.date
             
          }
      }
  });
  //日期范围
  var startDate=laydate.render({
      elem: '#dateOne',
    //  type: 'datetime',
      min:"2001-12-31",
      max:"2099-12-31",//设置一个默认最大值
      done: function(value, date){
          endDate.config.min ={
              year:date.year,
              month:date.month-1, //关键
              date: date.date
             
          };
      }
  });
  
  //日期
  laydate.render({
	    elem: '#dateOne'
  });
  laydate.render({
	    elem: '#dateTwo'
  });

  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
 
  
  //执行一个 table 实例
  table.render({
     elem: '#wholesale'
    ,async: false
    ,height: 374
    ,url: path+'wholesale/findAlls.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {field: 'pfId', title: '批发ID', width:120 }
  
      ,{field: 'pfSerialNumber', title: '流水号', width:120}
      ,{field: 'pfNumber', title: '数量', width:100,sort: true}
      ,{field: 'pfTotalMoney', title: '总金额', width:100,sort: true}
      ,{field: 'pfPerson', title: '批发人', width:80 }
      ,{field: 'pfDates', title: '批发时间', width:120,sort: true}
      ,{field: 'state', title: '状态', width:120}
      ,{field: 'isva', title: '是否有效', width:80}
      ,{field: 'filId', title: '分公司ID', width:120}
      ,{fixed: 'right',title: '操作', width: 205, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    var pfId = data.pfId;
    if(layEvent === 'del'){
      var pfId=data.pfId;
      layer.confirm('确认删除？', function(index){
        obj.del(); //删除对应行（tr）的DOM结构
        layer.close(index);
        //使用jquery的ajax方式向后台提交数据
		var url = path+"wholesale/deletePfId.action";
		var data={pfId:pfId};
		
			$.post(url,data,function(data){
				if(data=="ok"){
					layer.msg('删除成功', {
						  icon: 1,
						  time: 2000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
						  
					});
				}
			});
      	});
    } else if(layEvent === 'xgsh'){
	     
    	
    	layer.open({
			  type: 2,
			  area : ['75%' , '80%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: [path+'pages/mln/wholesaleUpdate.html?pfId='+pfId,'on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		 	 
		});
	}else if(layEvent === 'salesReturn'){
		var tuihuo = data.tuihuo;
		
		//判断退货与 已退货状态
    	if(tuihuo==0){
    		 layer.msg('订单已退货，无法操作', {
				  icon: 1,
				  time: 3000 //1秒关闭（如果不配置，默认是3秒）
				}, function(){
					// location.reload(); // 页面刷新
			});
    	}
		
		if(tuihuo==1){
			var pfId = data.pfId;
			//sessionStorage['sellId'] = sellId;
			layer.open({
				title:'分店批发详情'
				,type:2
				,area:['85%','80%']
				//设置滚蛋条 yes为开启  no为关闭
				,content:[path+'pages/mln/wholesaleDetail.html?pfId='+pfId,'yes']
			});
		}
		
 
    }else if(layEvent === 'detail'){
    	layer.open({
			title:'批发订单详情'
			,type:2
			,area:['75%' , '70%']
			,content:[path+'pages/mln/wholesaleList.html?pfId='+pfId,'yes']
		});
 
    }
    
    });

		//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			var demoReload = $('#demoReload');
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					pfPerson : demoReload.val(),
					dateOne: $("#dateOne").val(),
					dateTwo: $("#dateTwo").val(),
				}
			});
		});
		$('#closeAdd').on('click', function() {
			$('#addReload').css('display', 'none');
		});
		$('#closeUpdate').on('click', function() {
			
			$('#updateReload').css('display', 'none');
		});
		
		$('#memberAdd').on('click', function() {
			$('#addReload').css('display', 'block');
			
		});
	});
</script>
<script>

</script>
</body>
</html>